import { redisService } from './redis';
import { User } from "../model/user";
import { X } from 'e:/mjwork/xorm';
export class UserService {

    async getUserInfoByToken(token : string) : Promise<User | undefined>{
        if(!token || token == ''){
            return;
        }
        const user = await redisService.get("user:info:" + token);
        if(user){
            return user as User;
        }
        const ret = await X.of(User).findOne({
            where : {
                token : token
            }
        });
        if(ret){
            redisService.set("user:info:" + token,ret);
        }
        return ret;
    }
}

export const userService = new UserService;